<template>
    <div class="dh_staffdetails">
        
        <div class="dh_s-content" v-if="pageingstate != 3">
            <!-- 查询 -->
            <div class="dh_s-c-inquire">

                <el-form :model="kindinquire" ref="kindinquire" :inline="true" label-width="70px" class="dh_sci-form mb10 pl10 pr10">
                    <el-form-item label="查询项" class="mt20 mb20">
                        <el-select v-model="kindinquire.select" @change=";for(var r in kindinquire) r != 'select' ? kindinquire[r] = '' : ''">
                            <el-option label="商标文字" value="1"></el-option>
                            <el-option label="类别查询" value="2"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="商标文字" v-if="kindinquire.select === '1'" class="mt20 mb20">
                        <el-input v-model="kindinquire.id" placeholder="请输入查询的员工工号"></el-input>
                    </el-form-item>

                    <el-form-item label="下级分类" class="mt20 mb20" v-else>
                        <el-select v-model="kindinquire.topid">
                            <el-option v-for="(item,key) in kindselect" :key='key' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item class="mt20 mb20">
                        <el-button type="primary" @click="seektrade" class="p10 f18">查询</el-button>
                        <el-button type="danger" @click="requeststaff();for(var r in kindinquire) r != 'select' ? kindinquire[r] = '' : ''" class="p10 f18">取消查询</el-button>
                    </el-form-item>
                </el-form>

            </div>
            <!-- 列表数据 -->
            <div class="dh_s-c-list">
                <div class="bb1 mb10 pb10">
                    <button type="button" @click="goback" class="pt5 pr10 pb5 pl10 br5 wh bc4a"><i class="el-icon-caret-left f16"></i>返回员工页</button>
                    <el-badge :value="number.today" class="item mr10">
                        <el-button size="small" @click="pageingstate=1;total=number.today">今日</el-button>
                    </el-badge>
                    <el-badge :value="number.gross" class="item">
                        <el-button size="small" @click="pageingstate=0;total=number.gross">总量</el-button>
                    </el-badge>
                </div>
                <table class="dh_scl-table tc f14">
                    <thead>
                        <tr>
                            <th>所属员工ID</th>
                            <th>申请人名称<br/><span class='n f12 b00a'>*点员工姓名看详情</span></th>
                            <th>申请人地址</th>
                            <th>商标文字</th>
                            <th>类别</th>
                            <th>文件名称<span class="b00a cup" @click="requerstexcel">(导出Excel)</span></th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>

                    <tbody v-if='pageingstate === 1'>
                        <tr v-for="(item,key) in tradelist.slice(0,(number.today-((currentPage-1)*pagesize)))" :key="key">
                            <td>{{item.staffid}}</td>
                            <td>
                                <router-link :to="'/details/'+item.id" >{{item.name}}</router-link>
                            </td>
                            <td>{{item.address}}</td>
                            <td>{{item.word}}</td>
                            <td>{{item.kind}}</td>
                            <td>{{item.filename}}</td>
                            <td>{{item.createtime*1000 | formatDate}} {{item.createtime*1000 | formatDateBehind}}</td>
                            <td>
                                <button type="button" @click="dialogFormVisible=true;for(var i in tradeupdata) i!=='arrgoods' ? tradeupdata[i]=item[i]:tradeupdata[i]=[];tradeupdata.key=key" class="wh p10 br5 bc4a">修改</button>
                                <!-- <button type="button" @click="staffdelete(item.id,key)" class="wh p10 br5 bcfd">删除</button> -->
                                <button type="button" @click="download(item)" class="wh pt5 br5 p10 bcfb">下载</button>
                            </td>
                        </tr>
                    </tbody>

                    <tbody v-else>
                        <tr v-for="(item,key) in tradelist" :key="key">
                            <td>{{item.id}}</td>
                            <td>
                                <router-link :to="'/details/'+item.id" >{{item.name}}</router-link>
                            </td>
                            <td>{{item.address}}</td>
                            <td>{{item.word}}</td>
                            <td>{{item.kind}}</td>
                            <td>{{item.filename}}</td>
                            <td>{{item.createtime*1000 | formatDate}} {{item.createtime*1000 | formatDateBehind}}</td>
                            <td>
                                <button type="button" @click="dialogFormVisible=true;for(var i in tradeupdata) i!=='arrgoods' ? tradeupdata[i]=item[i]:tradeupdata[i]=[];tradeupdata.key=key" class="wh p10 br5 bc4a">修改</button>
                                <!-- <button type="button" @click="staffdelete(item.id,key)" class="wh p10 br5 bcfd">删除</button> -->
                                <button type="button" @click="download(item)" class="wh pt5 br5 p10 bcfb">下载</button>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <!-- 分页 -->
                <div class="dh_scl-block bt1 bcwh">
                    <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="currentPage"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next"
                    :total="total"
                    class=" pt5 pr10 pb5 pl10">
                    </el-pagination>
                </div>
            </div>
  
            <el-dialog title="修改员工信息" :visible.sync="dialogFormVisible" center :append-to-body='true' top="20vh" width="450px">

                <el-dialog width="40%" title=增加产品 :visible.sync="innerVisible" center append-to-body>
                    <div><span v-for="(item,key) in tradeupdata.arrgoods" :key="key" :class="['wh dib p2 mt5 mb5 ml5 mr5 br5 f12 wpnp',item.b === true ? 'bc4a' : 'bgb3']">{{item.a}}<span @click="cancel(item,key)"><i class="el-icon-close"></i></span></span></div>
                    <!-- <span class="wh bgb3 pt2 pb2 pl5 br5 f12 mr5 wpnp" v-for="(item,key) in tradeadd.arrgoods" :key="key">{{item.a}}<span @click="cancel(item,key)"><i class="el-icon-close"></i></span></span></div> -->
                    <div class="add-list bor1 br5">
                        <div class="add-list-titel df bb1">
                            <div class="a-l-t-input ml10"><el-input size="mini" placeholder="请输入内容" v-model="input1"></el-input></div>
                            <button class="bc4a br5 wh p5" type="button" @click="seekclassify">搜索</button>
                        </div>
                        <div><span @click="pitchon(items,keys)" class="wh bgb3 dib p2 mt5 mb5 ml5 mr5 br5 f12 bgb3 wpnp" v-for="(items,keys) in allsamllclass" :key="keys">{{items.a}}</span></div>
                        <div class='bt1'><el-pagination @current-change="optionalskip" :current-page.sync="currentPage3" :page-size="30" layout="total, prev, pager, next, jumper" :total="total3"></el-pagination></div>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="innerVisible = false">添加</el-button>
                    </div>
                </el-dialog>

                <p class="dxm-ltb-text tc red">*灰色是原信息，填好修改信息后点击确定，信息自动更新</p>

                <div class="dxm-ltb-message mt20 df">
                    <span class="xm-ltbm-title">商标文字</span>
                    <el-input class="dxm-ltbm-price" v-model="tradeupdata.address" max="220px" placeholder="请输入新的注册地址" clearable></el-input>
                </div>

                <div class="dxm-ltb-message mt20 df">
                    <span class="xm-ltbm-title">注册地址</span>
                    <el-input class="dxm-ltbm-price" v-model="tradeupdata.word" max="220px" placeholder="请输入新的商标文字" clearable></el-input>
                </div>

                <div class="dxm-ltb-message mt20 df">
                    <span class="xm-ltbm-title">新增产品</span>
                    <div>
                        <span v-for="(item,key) in tradeupdata.arrgoods" :key="key" v-if="item.b!==true" class="wh dib p2 mt5 mb5 ml5 mr5 br5 f12 wpnp bc4a">{{item.a}}<span @click="tradeupdata.arrgoods.splice(key,1)"><i class="el-icon-close"></i></span></span></div>
                        <span @click="innerVisible=true;entireclassify();upexamine(tradeupdata.id)"><i class="el-icon-circle-plus-outline f30 b00a"></i>
                    </span>
                </div>

                <div class="dxm-ltb-confirm mt20 tc">
                    <el-button type="primary" class="dxm-ltb-c-btn wh" @click="requestupdata">确定</el-button>
                </div>
                
            </el-dialog>

        </div>

        
        <!-- 添加新员工的部分 -->
        <!-- <div class="dh_s-addstaff" v-else>
            <div class="bb1 p10"><button type="button" @click="pageingstate = 0" class="wh p5 br5 f14 bc4a mr10">返回列表</button>新增员工</div>
            <el-form :model="staffform" ref="staffform" :rules="rules" label-width="80px" class="dh_s-a-form p20">
                <el-form-item label="员工姓名" prop='name'>
                    <el-col :span="7"><el-input type="name" v-model="staffform.name" placeholder="请输入新增员工姓名" clearable></el-input></el-col>
                </el-form-item>
                <el-form-item label="登录名称" prop='username'>
                    <el-col :span="7"><el-input v-model="staffform.username" placeholder="请输入登录的用户名" clearable></el-input></el-col>
                </el-form-item>
                <el-form-item label="登录密码" prop='password'>
                    <el-col :span="7"><el-input type="password" v-model="staffform.password" placeholder="请输入登录密码" clearable></el-input></el-col>
                </el-form-item>
                <el-form-item label="" prop='phone'>
                    <label slot="label" class="ws4">手 机 号</label>
                    <el-col :span="7"><el-input v-model="staffform.phone" placeholder="请输入新员工的手机号" clearable></el-input></el-col>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="addstaff('staffform')">提交</el-button>
                </el-form-item>
            </el-form>
        </div> -->
    </div>
</template>

<script>
const axios = require('axios');
import {timeday} from '../js/time.js'		 //用户日期转时间戳
// import {timeday} from '../js/time.js'
import {formatDate} from '../js/time.js';		 //直接在标签中转化时间的方法
let that
export default {
    components: {},
    data() {
        return {
            id: '',                             //接口传值，用来请求员工注册商标详情的
            token: '',
            tradelist: [],
            kindselect: [],                    //做类别名过滤用的
            allsamllclass:[],                  //全部小类的数组
            // 查询的绑定值
            kindinquire:{
                select: '1',
                word: '',
                kind: ''
            },
            // 添加员工的form表单绑定值
            staffform: {
                name: '',
                username: '',
                password: '',
                phone: ''
            },
            // 添加员工的表单验证
            rules:{
                name:[
                    { required: true, message: '请输入员工姓名', trigger: 'blur' },
                    { min: 2, max: 6, message: '长度在 2 到 4 个字符', trigger: 'blur' }
                ],
                username:[
                    {required: true, message: '请输入登录使用的用户名', trigger: 'blur'}
                ],
                password:[
                    {required: true, message: '请输入登录使用的密码', trigger: 'blur'}
                ],
                phone:[
                    { required: true, message: '请输入员工的手机号码', trigger: 'blur' },
                    { min: 11, max: 11, message: '十一位的数字', trigger: 'blur' }
                ]
            },
            // 修改
            tradeupdata:{
                id:'',
                address:'',
                word: '',
                arrgoods:[],
            },
            innerVisible: false,
            dialogFormVisible: false,
            pageingstate: 0,                   //彩笔使用的分页状态管理（区分数据运行）
            currentPage: 1,					   //分页的默认页数
            pagesize: 10,                      //单页条数
            total: 0,						   //总条数
            currentPage3: 1,
            total3: 0,
            input1: '',
            number:{today:'',gross:''}
        };
    },
    filters:{
        // 使用过滤器转化时间戳
        formatDate(time){
            var date = new Date(time);
            return formatDate(date,'yyyy-MM-dd');
        },
        formatDateBehind(time){
            var date = new Date(time);
            return formatDate(date,'hh:mm:ss')
        }
    },
    computed: {},
    watch: {},
    methods: {
        goback(){
            let that = this;
            that.$router.go(-1)
        },

        // 列表请求
        requesttrade(){
            let that = this;
            let data = {current:that.currentPage,size:that.pagesize,staffid:that.id};
            let updata = JSON.stringify(data);
            axios({
                method: 'post',
                url: '/api/trademarkInfo/list',
                headers: {
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                data: updata
            }).then( resp=> {
                // console.log(resp)
                that.tradelist = resp.data.data;
                that.total = resp.data.code;
                that.number.gross = resp.data.code;
            }).catch( err=> {})
        },

        // 提交修改内容
        async requestupdata(){
            let that = this;
            that.tradeupdata.arrgoods = that.tradeupdata.arrgoods.filter(item=> item.b!==true)
            let api,data;
            // console.log(that.tradeupdata)
            for(var i=0;i<2;i++){
                if(i===0){
                    data = {};
                    for(var p in that.tradeupdata) 
                    p==='arrgoods' ? '' : data[p] = that.tradeupdata[p];
                    api = '/api/trademarkInfo/update';
                }else{
                    that.tradeupdata.arrgoods.forEach(item=> item.trademarkInfoid = that.tradeupdata.id)
                    data = that.tradeupdata.arrgoods;
                    api = '/api/goods/batchAdd'
                }
                let updata = JSON.stringify(data)
                // console.log(updata)
                await axios({
                    method: 'post',
                    url: api,
                    headers: {
                        'Content-Type': 'application/json',
                        'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                    },
                    data: updata
                }).then( resp=> {
                    // console.log(resp)
                    if(i === 0){
                        for(var l in data) that.tradelist[that.tradeupdata.key][l] = data[l]
                        that.tradeupdata.arrgoods == "" ? i=2 : '';
                    }
                    that.dialogFormVisible = false
                }).catch( err=> {})
            }
        },

        // 拿到所有的大分类用作添加小分类选项使用，
        async requestselect(){
            let that = this;
            let total = 10,select;
            for(var i=0;i<2;i++){
                let that = this;
                let data = {current:1,size:total,level:0};
                let updata = JSON.stringify(data);
                // console.log(updata)
                await axios({
                    method: 'post',
                    url: '/api/kindAll/list',
                    headers: {
                        'Content-Type': 'application/json',
                        'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                    },
                    data: updata
                }).then(resp=>{
                    // console.log(resp,resp.data.data)
                    if(i === 0){
                        resp.data.code <= 10 ? (
                            that.kindselect = resp.data.data.map((item)=>{
                                return {
                                    id: item['id'],
                                    name: item['name']
                                }
                            }),i=2): total = resp.data.code;
                    }else{
                        that.kindselect = resp.data.data.map((item)=>{
                            return {
                                id: item['id'],
                                name: item['name']
                            }
                        })
                    }
                }).catch(err=>{})
            }
        },

        //自选的搜索分类
        seekclassify(){
            // let data = {}
            // console.log(that.input1)
            let data = {current:1,size:10,name:that.input1};
            let updata = JSON.stringify(data)
            axios({
                method: 'post',
                url: '/api/kindAll/list',
                headers:{
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                data: updata
            }).then( resp=> {
                // console.log(resp)
                let transform = resp.data.data.map((item)=>{
                    return {
                        a: item['name'],
                        kindAllid: item['id'],
                        b: item['namee'],
                    }
                })
                // console.log(transform)
                if(resp.data.data.length!== 0){

                    this.$message({
                        showClose: true,
                        message: '搜索到'+resp.data.data[0].name+'相关数据',
                        type: 'success'
                    })

                    this.$confirm('是否添加该小类?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        // that.tempform.arrname.push(transform[0])
                        // that.tempform.arrname.find(fruit => fruit.name === transform[0].name) === undefined ? (
                        //     that.tempform.arrname.push(transform[0]),
                        //     this.$message({type: 'success',message: '添加成功!'})
                        // ) : (
                        //     this.$message.error('已选择的分类不能重复添加')
                        // );
                        that.tradeupdata.arrgoods.find(fruit => fruit.a === transform[0].a) === undefined ? (
                            that.tradeupdata.arrgoods.push(transform[0]),
                            this.$message({type: 'success',message: '添加成功!'})
                        ) : (
                            this.$message.error('已选择的分类不能重复添加')
                        );
                        return
                        // this.$message({
                        //     type: 'success',
                        //     message: '添加成功!'
                        // });
                        // console.log(that.tempform.arrname)
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '取消添加'
                        });          
                    });
                }else{
                    this.$message.error('不存该校小类');
                }
                
            }).catch( err=> {})
        },

        // 分页的函数
        handleSizeChange(val) {
            // console.log(`每页 ${val} 条`);
            let that = this;
            this.pagesize = val;
            that.requesttrade()
            // if(that.pageingstate === 0){
            //     that.requeststaff()
            // }else if(that.pageingstate === 1){
            //     that.seekstaff()
            // }else{return}
        },
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            let that = this;
            that.currentPage = val
            that.requesttrade()
            // if(that.pageingstate === 0){
            //     that.requeststaff()
            // }else if(that.pageingstate === 1){
            //     that.seekstaff()
            // }else{return}
        },

        // 查询搜索
        seektrade(){
            let that = this;
            if(Number(that.kindinquire.select) === 1 && that.kindinquire.name === ''){
                return that.$message({
                    showClose:true,
                    message: '员工姓名不能为空',
                    type: 'warning'
                })                
            }else if(Number(that.kindinquire.select) === 2 && that.kindinquire.id === ''){
                return that.$message({
                    showClose:true,
                    message: '员工ID不能为空',
                    type: 'warning'
                })                           
            }else{
                let data = {current:that.currentPage,size:that.pagesize};
                for(var i in that.kindinquire){
                    that.kindinquire[i] !== '' && i !== "select" ? data[i] = that.kindinquire[i] : '';
                }
                let updata = JSON.stringify(data);
                // console.log(updata)
                axios({
                method: 'post',
                url: '/api/trademarkInfo/list',
                headers:{
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                data: updata
                })
                .then( resp=> {
                    // console.log(resp)
                    that.pageingstate = 1;
                    that.trademarkInfolist = resp.data.data
                    that.total = resp.data.code;
                    this.$message({
                        showClose: true,
                        message: '搜索到'+resp.data.code+'条数据',
                        type: 'success'
                    })
                })
                .catch( err=> {})
            }
        },

        // 添加新员工
        addstaff(formverify){
            let that = this;
            that.$refs[formverify].validate((valid)=>{
                if(valid){
                    let data = {};
                    // 表单对象与上传字段相同，for in循环赋值加去除空值
                    for(var o in that.staffform)
                    that.staffform[o] !== '' ? data[o] = that.staffform[o] : delete data[o]
                    let updata = JSON.stringify(data)
                    // console.log(updata)
                    axios({
                        method: 'post',
                        url: '/api/staff/add',
                        headers:{
                            'Content-type': 'application/json',
                            'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                        },
                        data: updata
                    }).then( resp=> {
                        // console.log(resp)
                        if(/^[0-9]*$/.test(resp.data.data)){
                            that.stafflist.length < that.pagesize ? that.stafflist.push(data) : '';
                            that.total += 1;
                        }else{return}
                    }).catch( err=> {})
                    that.$message({
                        showClose: true,
                        message: '添加成功，可以在员工列表中找到该员工的信息',
                        type: 'success'
                    })
                }else{
                    return false
                }
            })
        },

        // 修改员工数据
        updatastaff(){
            let that = this;
            let data = {}
            for(var o in that.staffupdata)
            o!="key" && that.staffupdata[o]!=='' ? data[o] = that.staffupdata[o] : delete data[o];
            let updata = JSON.stringify(data)
            this.$confirm('请再确认一下提交信息，无误后点击提交即可完成修改','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(()=>{
                that.outerVisible = false
                axios({
                    method: 'post',
                    url: '/api/staff/update',
                    headers:{
                        'Content-Type': 'application/json',
                        'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                    },
                    data: updata
                }).then( resp=>{
                    // console.log(resp)
                    for(var t in data)
                    that.stafflist[that.staffupdata.key][t] = data[t]
                }).catch(err=>{})
                this.$message({
                    type: 'success',
                    message: '修改成功'
                })
            }).catch(()=>{
                this.$message({
                    type: 'info',
                    message:'已取消修改'
                })
            })
        },

        // 删除
        staffdelete(id,key){
            let that = this;
            let data = {id: id};
            let updata = JSON.stringify(data);
            this.$confirm('删除员工后相应的数据页无法找到，确定要删除吗？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(()=>{
                axios({
                    method: 'post',
                    url: '/api/staff/delete',
                    headers: {
                        'Content-type': 'application/json',
                        'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                    },
                    data: updata
                }).then( resp=> {
                    // console.log(resp)
                    if(resp.data.data === "删除成功！"){
                        that.stafflist.splice(key,1);
                        that.total--
                        that.stafflist.length === 0 ? (that.currentPage-=1,that.requeststaff()) : '';
                    }else{return}
                }).catch( err=> {})
                this.$message({
                    type: 'success',
                    message: '成功删除'
                })
            }).catch(()=>{
                this.$message({
                    type: 'info',
                    message:'已取消删除'
                })
            })
        },

        // 获取全部小类
        entireclassify(){
            let that = this;
            let data = {current:that.currentPage3,size:30,level:1};
            let updata = JSON.stringify(data);
            axios({
                method: 'post',
                url: '/api/kindAll/list',
                headers: {
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                data: updata
            }).then( resp=> {
                // console.log('全部的小类',resp)
                that.allsamllclass = resp.data.data.map((item)=>{
                    return {
                        a: item['name'],
                        b: item['namee']
                    }
                }) 
                that.total3 = resp.data.code;
            }).catch( err=> {})
        },
        // 自选的跳页
        optionalskip(val){
            let that = this;
            that.currentPage3 = val
            that.entireclassify()
        },

        // 修改的弹窗显示已添加的小类
        async upexamine(id){
            let that = this;
            // console.log(id)
            if(that.tradeupdata.arrgoods == ''){
                // console.log('看看是不是每次都通过')
                let own = 10,select;
                for(var i=0;i<2;i++){
                    let data = {trademarkInfoid:id,current:1,size:own};
                    let updata = JSON.stringify(data);
                    // console.log(updata)
                    await axios({
                        method: 'post',
                        url: '/api/goods/list',
                        headers: {
                            'Content-Type': 'application/json',
                            'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                        },
                        data: updata
                    }).then( resp=> {
                        // console.log(resp)
                        if(i===0){
                            resp.data.code <= 10 ? (
                                select = resp.data.data.map((item)=>{ return {
                                    a: item['a'],
                                    b: true
                                }}),i=2) : own = resp.data.code;
                        }else if(resp.data.code > 10){
                            select = resp.data.data.map((item)=>{
                                return {
                                    a: item['a'],
                                    b: true
                                }
                            })
                        }
                        // that.total = resp.data.code;
                    }).catch( err=> {
                        // 
                    })
                }
                select.forEach(item=> that.tradeupdata.arrgoods.unshift(item))
                // console.log(that.tradeupdata.arrgoods)
            }else{return}
        },

        cancel(item,key){
            let that = this;
            // if(that.pageingstate === 2){
            //     that.tradeadd.arrgoods.splice(key,1)
            //     that.allsamllclass.find(fruit => fruit.a === item.a) === undefined ? (that.allsamllclass.push(item)) : '';
            // }else{
                that.tradeupdata.arrgoods.splice(key,1)
                that.allsamllclass.find(fruit => fruit.a === item.a) === undefined ? (that.allsamllclass.push(item)) : '';
            // }  
        },

        pitchon(item,key){
            let that = this;
            // if(that.pageingstate === 2){
            //     that.tradeadd.arrgoods.find(fruit => fruit.a === item.a) === undefined ? (that.tradeadd.arrgoods.push(item),that.allsamllclass.splice(key,1)) : this.$message.error('已选择的分类不能重复添加');
            // }else{
                // console.log(that.tradeupdata)
                that.tradeupdata.arrgoods.find(fruit => fruit.a === item.a) === undefined ? (that.tradeupdata.arrgoods.push(item),that.allsamllclass.splice(key,1)) : this.$message.error('已选择的分类不能重复添加');
            // }
        },

        // 下载
        async download(item){
            let that = this;
            axios({
                method: 'get',
                url:"/api/file/download?fileName=" + item.filename,
                // data:userjson,
                headers:{
                    'Content-Type':'application/json'  ,//如果写成contentType会报错
                    // "Authorization": "berare dhzn447d75e30a3c8579cf0eff666d56a283",
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                responseType: 'blob', //二进制流
            }).then(function (res) {
                if(!res) return
                let blob = new Blob([res.data]
                // {type: 'application/vnd.ms-excel;charset=utf-8'},
                )
                let url = window.URL.createObjectURL(blob);
                let aLink = document.createElement("a");
                aLink.style.display = "none";
                aLink.href = url;
                aLink.setAttribute("download", item.filename);
                document.body.appendChild(aLink);
                aLink.click();
                document.body.removeChild(aLink); 
                window.URL.revokeObjectURL(url); 
            }).catch(function (error) {});
        },

        // excel表
        requerstexcel(){
            let that = this;
            axios({
                method: 'post',
                url: '/api/excel/exportExcel',
                headers:{
                    'Content-Type':'application/json',//如果写成contentType会报错
                    // "Authorization": "berare dhzn447d75e30a3c8579cf0eff666d56a283",
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                responseType: 'blob', //二进制流
            }).then( resp=> {
                    
                    let blob = resp.data;
                    const fileReader = new FileReader(); // FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件的内容
                    fileReader.readAsDataURL(blob); // 开始读取指定的Blob中的内容。一旦完成，result属性中将包含一个data: URL格式的Base64字符串以表示所读取文件的内容
                    fileReader.onload = (event) => { // 处理load事件。该事件在读取操作完成时触发
                        // 新建个下载的a标签，完成后移除。
                        let a = document.createElement('a');
                        let _fileName = '数据表格.xls';
                        a.download = _fileName;
                        a.href = event.target.result; 
                        document.body.appendChild(a);
                        a.click();
                        document.body.removeChild(a);
                    }

            })
        },

        requestday(){
            let that = this;
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            let time = timeday(year + "-" + month + "-" + day+' '+'00:00:00')
            let data = {
                current:that.currentPage,
                size:30,
                createTime: time,
                staffid:that.id
            };
            let updata = JSON.stringify(data);
            // console.log(updata)
            axios({
                method:'post',
                url: '/api/dayNum/list',
                headers:{
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`
                },
                data: updata
            }).then( resp=> {
                // console.log('每日更新',resp)
                
                that.number.today = resp.data.data[0].number
                
            }).catch( err=>{})
        },
    },
    created() {},
    mounted() {
        let that = this;
        that.id = this.$route.params.aid;
        that.token = JSON.parse(sessionStorage.getItem('token'));
        // console.log(that.token)
        that.requestday()
        that.requesttrade();
        that.requestselect();
    },
    beforeCreate() {
        that = this;
    },
    beforeMount() {},
    beforeUpdate() {},
    updated() {},
    beforeDestroy() {},
    destroyed() {},
    activated() {},
    }
</script>
<style scoped>
.dh_staffdetails{
    height: 100%;
}
.dh_s-content{
    height: 100%;
}
/* 查询 */
.dh_sci-form{
    background-color: #ffffff;
    box-shadow: 0 0 2px #4b4b4b;
    border-radius: 5px;
}
/* 列表数据 */
.dh_s-c-list{
    display: flex;
    flex-direction: column;
    height: calc(100% - 91px);
    padding: 10px;
    background-color: #ffffff;
    border-radius: 5px;
    box-sizing: border-box;
    box-shadow: 0 0 2px #4b4b4b;
}
.dh_scl-table{
    width: 100%;
    border-collapse: collapse;
    border-bottom: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
    border-spacing: 0;/*去掉单元格间隙*/
}
.dh_scl-table th{
    background-color: #ececec;
}
.dh_scl-table tbody tr:hover{
    background-color: #ececec;
}
.dh_scl-table th,.dh_scl-table td{
    padding: 10px 0;
    border-left:1px solid #e0e0e0;
    border-top:1px solid #e0e0e0;
}
/* 分页 */
.dh_scl-block{
    margin-top: auto;
}

/* 加员工 */
.dh_s-addstaff{
    /* height: 100%; */
    background-color: #ffffff;
    border-radius: 5px;
    box-shadow: 0 0 3px #3d3d3d;
}
.el-form-item__label{
    border-bottom: 1px solid #e7e7e7;
}

/* 修改的弹窗 */
.dxm-ltb-message{
    display: flex;
    align-items: center;
}
.xm-ltbm-title{
    min-width: 80px;
}
</style>